/**
 * 
 */
package boundary.components;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPopupMenu;

/**
 * @author davide
 *
 */
public class PopupListener extends MouseAdapter
{
    JPopupMenu popmenu;
    
    public PopupListener(JPopupMenu pmenu)
    {
	this.popmenu = pmenu;
    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
     */
    @Override
    public void mousePressed(MouseEvent e)
    {
	this.maybeShowPopup(e);
    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseReleased(MouseEvent e)
    {
	this.maybeShowPopup(e);
    }
    
    private void maybeShowPopup(MouseEvent e)
    {
	if (e.isPopupTrigger())
	{
	    this.popmenu.show(e.getComponent(), e.getX(), e.getY());
	}
    }
}
